/**
 * package: seeds
 * author: zhaiyujin
 * description:
 */
package seeds

import (
	"fmt"
	"github.com/casbin/casbin/v2"
	"gorm.io/gorm"
	"os"
)

//初始化seed
func HookSeeds(db *gorm.DB,enforcer *casbin.Enforcer)  {
	SeedAdmin(db)
	SeedRoles(db)
	SeedAdminRole(db)
	SeedMenu()
	SeedRoleMenu(db)
	SeedCasbin(db,enforcer)
}
//注册更新的seed
func HookUpdateSeeds(db *gorm.DB){

}


func Seeds(db *gorm.DB,enforcer *casbin.Enforcer)  {
	fmt.Println("数据填充准备...")
	_,err:=os.Stat("data/data.lock")

	//如果已经存在文件
	if err==nil {
		return
	}

	HookSeeds(db,enforcer)

	newFile, err := os.Create("data/data.lock")
	if err != nil {
		panic("数据填充失败")
	}
	newFile.Close()

	HookUpdateSeeds(db)
}
